package com.leetcode.数组;

public class 合并两个有序数组 {
    public void merge(int[] num1, int m, int[] num2, int n) {
        // int[] num1 = {1,3,5,0,0,0}
        // int[] num2 = {2,4,6}
        int i1 = m - 1;
        int i2 = n - 1;
        int cur = num1.length - 1;

        while (i2 >= 0) {
            if (i1 >= 0 && num1[i1] > num2[i2]) {
                num1[cur--] = num1[i1--];
            } else { // num1[i1] < num2[i2] || i1 < 0
                num1[cur--] = num2[i2--];
            }
        }
    }
}
